﻿using ECommon.Components;
using ENode.EQueue;
using ENode.Eventing;
namespace QuickStart
{
    using Commands.Accounts;
    using Domain.Accounts;
    using ENode.Commanding;
    using ENode.Infrastructure;
    using Infrastructure;

    // 只有生产者（发送端）需要定义发到哪个topic去。
    // 接收的通过代码进行订阅

    [Component]
    public class CommandTopicProvider : AbstractTopicProvider<ICommand>
    {
        //public CommandTopicProvider()
        //{
        //    RegisterTopic(Topics.DefaultCommand, typeof(RegisterNewAccountCommand), typeof(SignInAfterCommand), typeof(SignOutAfterCommand));
        //    //RegisterTopic("SectionCommandTopic", typeof(CreateSectionCommand), typeof(ChangeSectionNameCommand));
        //}

        public override string GetTopic(ICommand source)
        {
            return Topics.DefaultCommand;
        }
    }



    [Component]
    public class EventTopicProvider : AbstractTopicProvider<IDomainEvent>
    {
        //public EventTopicProvider()
        //{
        //    RegisterTopic(Topics.DetaultEvent, typeof(NewAccountRegisteredEvent), typeof(SignInAfterEvent), typeof(SignOutAfterEvent));
        //    //RegisterTopic("SectionEventTopic", typeof(SectionCreatedEvent), typeof(SectionNameChangedEvent));
        //}

        public override string GetTopic(IDomainEvent source)
        {
            return Topics.DetaultEvent;
        }

    }



    [Component]
    public class ApplicationMessageTopicProvider : AbstractTopicProvider<IApplicationMessage>
    {
        public override string GetTopic(IApplicationMessage applicationMessage)
        {
            //if (applicationMessage is CreatePaymentMessage || command is CompletePayment || command is CancelPayment)
            //{
            //    return Topics.PaymentCommandTopic;
            //}
            return Topics.DetaultApplicationMessage;
        }
    }


    [Component]
    public class ExceptionTopicProvider : AbstractTopicProvider<IPublishableException>
    {
        public override string GetTopic(IPublishableException exception)
        {
            return Topics.DetaultPublishableException;
        }
    }
}
